include $(TOPDIR)/rules.mk

PKG_NAME:=stalwartlabs
PKG_VERSION:=v0.11.5
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/stalwartlabs/mail-server.git
#PKG_SOURCE_DATE:=2025-02-09
PKG_SOURCE_VERSION=b1d6e7171508939a2313021ec8bf0606fd5ebbfc
PKG_MIRROR_HASH:=skip

PKG_LICENSE:=MIT
PKG_MAINTAINER:=JoyNine<joyplayer@126.com>
#PKG_CPE_ID:=cpe:/a:powerdns:recursor

PKG_FIXUP:=autoreconf
PKG_BUILD_DEPENDS:=rust/host
PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1

include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/feeds/packages/lang/rust/rust-values.mk

define Package/stalwartlabs
  SECTION:=mail
  CATEGORY:=Mail
#  USERID:=pdns:pdns
  TITLE:=A mail server in Rust.
  DEPENDS:=+boost +boost-context +boost-filesystem +libatomic +liblua +libopenssl +libfstrm +libcurl
  URL:=https://github.com/stalwartlabs/mail-server
endef

define Package/stalwartlabs/description
 Stalwart Mail Server is an open-source mail server solution with JMAP, IMAP4, POP3, and SMTP support and a wide range of modern features. 
 It is written in Rust and designed to be secure, fast, robust and scalable.
endef

define Package/stalwartlabs/conffiles
/etc/init.d/stalwartlabs
endef

# not everything groks --disable-nls
DISABLE_NLS:=

CONFIGURE_ARGS += \
	--manifest-path=crates/main/Cargo.toml \
        --no-default-features \
	--features mysql \
	--release
	

MAKE_VARS += RUSTC_TARGET_ARCH=$(RUSTC_TARGET_ARCH)
MAKE_VARS += RUST_TARGET=--target=$(RUSTC_TARGET_ARCH)

define Package/stalwartlabs/install
	$(INSTALL_DIR) $(1)/usr/bin
endef

$(eval $(call BuildPackage,stalwartlabs))

